import { createStore,combineReducers } from "redux";
// import reducers from '../reducers';

// 单数据合并
// const initialState = {
//   number: 11,
// };

// const reducers = (state = initialState, action) => {
//   switch (action.type) {
//     // case actionTypes.ADD_TEST:
//     case "1":
//       return {
//         ...state,
//         number: action.number + 1,
//       };
//     default:
//       return state;
//   }
// };

//---------------------------------------------------------------
const initialState = {
  number: 11,
};
const doSomethingWithA = (state = initialState, action) => {
  // console.log(state,action,'===========state,action')
  switch (action.type) {
    // case actionTypes.ADD_TEST:
    case "1":
      return {
        ...state,
        number: action.number + 1,
      };
    default:
      return state;
  }
};
const doSomethingWithB = (state = initialState, action) => {
  // console.log(state,action,'===========state,action')
  switch (action.type) {
    // case actionTypes.ADD_TEST:
    case "2":
      return {
        ...state,
        number: action.number + 1,
      };
    default:
      return state;
  }
};


// 多数据合并
const reducers = combineReducers({
  a: doSomethingWithA,
  b: doSomethingWithB,
  // c: c
})

// 等同于
// function reducers(state = {}, action) {
//   console.log(state,'state')
//   return {
//     // 类似 vuex module模块
//     a: doSomethingWithA(state.a, action),
//     // b: doSomethingWithB(state.b, action),
//     // c: c(state.c, action)
//   }
// }



const store = createStore(reducers,{a:{number:33}});//vue data 函数创建不同的 store  覆盖默认值


console.log(store,'=================555')
console.log(store.getState(), " store.getState();==============="); //获取数据

let time=store.subscribe (function(res){  //vue watch方法 改变监听(定时器 )
  console.log(res,store.getState(),'================res')
})
time() //删除功能

store.dispatch ({                 // 更新了    //方法处理
  // type: actionTypes.ADD_TEST,
  type:'1',
  number: store.getState().a.number
})


export default store;
